//Start - Reload Document
$(function(){
	
	//Start - Add comma to numbers every three digits
	$("tbody .report_totalprice").digits();
	//End - Add comma to numbers every three digits
	
	//Start - Statistic Validation
	 $('#FormStatistic').bootstrapValidator({
//        live: 'disabled',
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            statistic_orderfrom: {
                validators: {
                    notEmpty: {
                        message: 'Order From Date is required and cannot be empty'
                    }
                }
            },
			statistic_orderto: {
                validators: {
                    notEmpty: {
                        message: 'Order To Date is required and cannot be empty'
                    }
                }
            }
        }
    });
	//End - Statistic Validation
	
	//Start - Admin comment Validation
	 $('#FormAdminComment').bootstrapValidator({
//        live: 'disabled',
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            comment_admin: {
                validators: {
                    notEmpty: {
                        message: 'Your Comment is required and cannot be empty'
                    }
                }
            }
        }
    });
	//Reset the form whenever Modal is show
	$('#basicModalAdminComment').on('show.bs.modal', function() {
   		 //$('#FormAdminComment').bootstrapValidator('resetForm', true);
	});
	//End - Admin comment Validation
	
	
	//Start - dataTable
	$('#adm_productlist, #adm_catlist, #comment_table, #table_orderlist').dataTable();
	 $('#statistic_report').dataTable( {
        "paging":   false,
        "ordering": false,
        "info":     false,
		"searching":false
    } );
	//End - dataTable
	
	//Start - Hover on header dropdownlist
	$('ul.nav li.dropdown').hover(function() {
 		$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
		}, function() {
 	 		$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
	});
	//End - Hover on header dropdownlist
	
	
	 //Start - Set current link on Nav
	var path = window.location.href;
    path = decodeURIComponent(path);
	path = $.trim(path.substring(path.lastIndexOf("/")+1,path.length));
		//alert($.trim(path));	
		$(".navbar-nav li a").each(function () {
        var href = $.trim($(this).attr('href'));
        if (path === href) {
			$(this).closest('li').siblings().removeClass("active");
            $(this).closest('li').addClass('active');
        }
   		 });
		
		if(path.indexOf("Category")>=0){
			if(path.indexOf("Gender=0")>=0){
				$(".navbar-nav li a[href *='Gender=0']").closest('li').addClass('active');
				$(".navbar-nav li a[href *='Gender=0']").closest('li').siblings().removeClass("active");
				}
			else if (path.indexOf("Gender=1")>=0){
				$(".navbar-nav li a[href *='Gender=1']").closest('li').addClass('active');
				$(".navbar-nav li a[href *='Gender=1']").closest('li').siblings().removeClass("active");
				}
				
			$(".cat_left_menu a").each(function () {
			var href = $.trim($(this).attr('href'));
			if (path === href) {
				$(this).siblings().removeClass("lef_menu_active");
				$(this).addClass('lef_menu_active');
			}
			 });
		}
		 
	//End - Set current link on Nav
});
//End - Reload Document


function getCommentbyId(value){
	
	var comContent = $("#" + value).parents("tr").find(".comment_conent").html();
	var adminComment = $("#" + value).parents("tr").find(".comment_answer").html();
	var comId = value.substring(value.lastIndexOf("_")+1,value.lengh);
	
	$("#comment_content").html(comContent);
	$("#comment_admincomment").html(adminComment);
	$("#hdcomment_commentid").attr('value',comId);
}

function updateOrderStatus(value){
	var orderStauts = $("#" + value).parents("tr").find("select.order_status").val();
	var orderId = value.substring(value.lastIndexOf("_")+1,value.lengh);
	//alert (orderId)
	
	$.ajax({
				type:'POST',
				url:'Utility/UUpdateOrderStatus.asp',
				data: {
					OrderId: orderId,
					OrderStauts: orderStauts
				},	
				dataType: 'html',
				success: function(msg){
					//alert(msg)
					if(msg == "UpdateOrderStatusSuccess"){
						$("#basicModalUpdateOrderStatus").modal("show");
					}
				}
		});
}


$.fn.digits = function(){ 
    return this.each(function(){ 
        $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") ); 
    })
}